package Repository;

import java.util.ArrayList;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;	
import org.xml.sax.helpers.DefaultHandler;

/**
*
* Rivera, Valencia, De Grano, Tan, Macatangay
*/
public class FeatureRepositoryHandler extends DefaultHandler
{
	private ArrayList<FeatureRepository> RespList = new ArrayList<FeatureRepository>();
	private ArrayList<FeatureListing> Listing;
	
	private FeatureRepository Resp;
	private FeatureListing tempList;
	
	private boolean label = false;
	private boolean name = false;
	private boolean value = false;
	
	public void startElement(String uri, String localName,String qName,Attributes attributes) throws SAXException 
	{		
		if(qName.equalsIgnoreCase("type"))
		{
			Resp = new FeatureRepository();
			Listing = new ArrayList<FeatureListing>();
		}
	
		if(qName.equalsIgnoreCase("label"))
			label = true;
		
		if(qName.equalsIgnoreCase("name"))
		{
			name = true;
			tempList = new FeatureListing();
		}
	}
	
	public void characters(char ch[], int start, int length) throws SAXException 
	{
		if(label)
		{
			Resp.setLabel(new String(ch,start,length));
			label = false;
		}
		if(name)
		{
			tempList.setName(new String(ch,start,length));
			name = false;
		}
		if(value)
		{
			tempList.getValues().add(new String(ch,start,length));
		}
	}
	
	public void endElement(String uri, String localName,String qName) throws SAXException 
	{
		if(qName.equalsIgnoreCase("name"))
		{
			value = true;
		}
	
		if(qName.equalsIgnoreCase("features"))
		{
			value = false;
			Listing.add(tempList);
		}
		
		if(qName.equalsIgnoreCase("type"))
		{
			Resp.setListing(Listing);
			RespList.add(Resp);
		}
	}
}
